﻿
@{
    ViewBag.Title = "保证金规则设置";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}

@model List<Himall.Model.CategoryCashDepositInfo>
<link href="~/Content/bootstrap-switch.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap-switch.min.js"></script>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>保证金</strong>
        <li><a href="Management">保证金管理</a></li>
        <li class="active"><a>保证金规则设置</a></li>
    </ul>
    <h5><span class="help-default">平台可根据商城的一级分类设置经营该类目的商家应缴纳保证金，商家缴纳相应保证金后，可在商品详情页、店铺首页及订单列表页面出现消费者保障标识；

当商家同时经营多个一级类目时则按最高值缴纳；

当开启七天无理由退换后，在缴纳保证经卖家的商品详情页面、店铺首页及订单列表页面将出现七天无理由退换货标识

        <a href="/admin/Article/Add"><h5>去设计保证金相关文章</h5></a>
</span></h5>

    <table class="table">
        <thead>
            <tr>
                <th align="center">类目</th>
                <th align="center">应缴金额（元）</th>
                <th align="center">七天无理由退换货</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var c in Model)
            {
                <tr>
                    <td>
                        @c.CategoriesInfo.Name
                    </td>
                    
                    <td>
                        <input class="text-order" onchange="updateNeedpay(@c.CategoryId,$(this))"  type="text" value="@c.NeedPayCashDeposit" />
                    </td>

                    <td>
                        <div class="switch switch-mini">
                            <input class="bootstrapSwitch" categorycashdepositid="@c.CategoryId" enablenoreasonreturn="@c.EnableNoReasonReturn" type="checkbox" data-on-text="开启" @(@c.EnableNoReasonReturn ? "checked" : "") data-off-text="关闭" />
                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>

</div>
<script>
    $(function () {
            $(".bootstrapSwitch").bootstrapSwitch({
                onSwitchChange: function (event, state) {
                    var categoryCashDepositId = $(this).attr('categorycashdepositid');
                    var enableNoReasonReturn = $(this).attr('enablenoreasonreturn');
                    var url = "CloseNoReasonReturn";
                    if (state)
                        url = "OpenNoReasonReturn";
                    var switcher = $(this);
                    var loading = showLoading();
                    $.post(url, { categoryId: categoryCashDepositId }, function (result) {
                        loading.close();
                        if (result.Success) {
                            switcher.bootstrapSwitch('state', state);
                        }
                        else {
                            switcher.bootstrapSwitch('state', !state);
                            $.dialog.errorTips('操作失败!失败原因：' + result.msg);
                        }
                    }, "json");

                }
            });
        });

    function updateNeedpay(id,obj)
    {
        var cashDeposit=obj.val()
        var loading = showLoading();
        $.post('UpdateNeedPayCashDeposit', { categoryId: id,cashDeposit: cashDeposit}, function (result) {
            loading.close();
            if(result.Success)
            {
                $.dialog.tips("修改成功");
            }
            else
                $.dialog.errorTips("修改失败"+result.msg);
        });
    }
</script>